
/* action.vala
 *
 * Copyright (C) 2008  Frederik 'playya' Sdun
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Author:
 *     Frederik 'playya' Sdun <Frederik.Sdun@gmail.com>
 */
using GLib;
using Rob;

namespace Rob
{
    namespace Actions
    {
        public interface IAction: GLib.Object
        {
            public abstract string name {get; set; }
            public abstract string title { get; set; }
            public abstract bool run();
            public abstract bool stop();
            public abstract bool running{ get;}
            public abstract bool load( GLib.KeyFile kf, string name ) throws KeyFileError;
            public abstract bool save( GLib.KeyFile kf );
        }

        public class Action: GLib.Object, Rob.Actions.IAction, Rob.ILoadable
        {
            protected string _title;
            protected string _name;
            protected string _type;
            protected bool is_running;
            public bool running{get{return this.is_running;}}
            public string name
            {
                get{return _name;}
                set{_name = value;}
            }
            public string title
            {
                get{ return _title;}
                set{ _title = (value==null)?"":value;}
            }    
            
            construct
            {
                            string full_path = "%s/actions/%s".printf( Rob.BASE_OBJ_PATH,this.name  );
                            Rob.connection.register_object( full_path, this );
            }
            public virtual bool run(){return false;}
            public virtual bool stop(){return false;}
            public virtual bool load( GLib.KeyFile kf, string name) throws KeyFileError
            {
                this._name = name;
                this._type = kf.get_string(name,"type");
                this._title = kf.get_string(name,"title");
                return true;
            }
            public virtual bool save(GLib.KeyFile kf) 
            {
                kf.set_string(this._name,"type", this._type );
                kf.set_string(this._name,"title", this._title );
                return true;
            }
        }
    }
}
